package com.supermap.dataservice.count.cq;

import com.alibaba.dubbo.config.annotation.Service;
import com.supermap.dataservice.expert.cq.CqExpertProductMpper;
import com.supermap.dataservice.mysql.config.DynamicDataSourceContextHolder;
import com.supermap.dataservice.project.cq.CqProductMapper;
import com.supermap.dataservice.util.JSONUtil;
import com.supermap.dataservice.util.Table;
import com.supermap.dataservice.vip.cq.CqVipProductMapper;
import com.supermap.dubbo.api.cq.epproduct.CountEPCountSumService;
import com.supermap.dubbo.api.cq.epproduct.CountEPV;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author aqua
 * @description 统计全重庆的专家专业产品
 * @date 2018年11月09 下午 4:53
 * @email 1301584033@qq.com
 */
@Service
public class CountEPCountSumServiceImpl implements CountEPCountSumService {

    @Resource
    private CqProductMapper cqProductMapper;

    @Resource
    private CqExpertProductMpper cqExpertProductMpper;

    @Resource
    private CqVipProductMapper cqVipProductMapper;



    @Override
    public List<Map<String, Object>> getProfvipcontentFarmById(String farmId, String pageNum, String pageSize) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds1");
        return   cqVipProductMapper.getCqProfvipcontent(farmId,pageNum,pageSize);
    }

    @Override
    public Table getCqPEVProductCountSum(String beginTime, String endTime) {
        // 切换数据源
        DynamicDataSourceContextHolder.setDataSourceKey("ds1");
        List<CountEPV> countEPVList=new ArrayList<>();
          List<Map<String,Object>> mapPList = cqProductMapper.getCqProductCountNum(beginTime,endTime,"0","200");
          List<Map<String,Object>> mapEList=cqExpertProductMpper.getCqExpertProductCountNum(beginTime,endTime,"0","200");
        List<Map<String,Object>> mapVList=cqVipProductMapper.getVipProductCountNum(beginTime,endTime,"0","200");
          if(mapPList!=null&&mapEList!=null){
              for (int i=0;i<mapPList.size();i++){
                  CountEPV countEPV=new CountEPV();
                  countEPV.setAreaCode( mapPList.get(i).get("depareacode").toString()==null?"":mapPList.get(i).get("depareacode").toString());
                  countEPV.setAreaName(mapPList.get(i).get("departname").toString()==null?"":mapPList.get(i).get("departname").toString());
                  countEPV.setCountProduct(mapPList.get(i).get("num").toString()==null?0:Integer.valueOf(mapPList.get(i).get("num").toString()));
                  countEPV.setCountExpertProduct(mapEList.get(i).get("num").toString()==null?0:Integer.valueOf(mapEList.get(i).get("num").toString()));
                  countEPV.setCountVipProduct(mapVList.get(i).get("num").toString()==null?0:Integer.valueOf(mapVList.get(i).get("num").toString()));
                  countEPVList.add(countEPV);
              }
          }
        Table table=new Table();
        table.setData(countEPVList);
        return table;
    }

    @Override
    public Table getCqProductListByAreaCode(String beginTime, String endTime, String areaCode) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds1");
        List<Map<String,Object>> mapList=cqProductMapper.getCqProductListByAreaCode(beginTime,endTime,areaCode);
        Table table=new Table();
        table.setData(mapList);
        return table;
    }

    @Override
    public Table getCqProductListByAreaCodeDetails(String beginTime, String endTime, String areaCode, String baseClassId) {
        DynamicDataSourceContextHolder.setDataSourceKey("ds1");
        List<Map<String,Object>> mapList=cqProductMapper.getCqProductListByAreaCodeDetails(beginTime,endTime,areaCode,baseClassId);
        Table table=new Table();
        table.setData(mapList);
        return table;
    }




}
